from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
import unittest
import pytest
from test.login import login
from time import sleep


class test_deleteuser(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.driver = webdriver.Chrome()
        cls.driver.get("http://localhost:8080")
        cls.driver.implicitly_wait(5)

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()

    def delete_user(self):
        # 打开后窗口最大化
        self.driver.maximize_window()
        # 导入test_login中的test_login类中的login方法
        login.login(self)
        self.driver.implicitly_wait(10)
        self.driver.find_element(By.XPATH, "//*[@id='fsLeftMenu']/li[1]/dl/dd[1]/a").click()
        self.driver.implicitly_wait(10)
        iframe1 = self.driver.find_element(By.XPATH, "/html/body/div[2]/form/div[4]/div/div/div[2]/iframe")
        self.driver.switch_to.frame(iframe1)
        self.driver.implicitly_wait(10)
        enter_btn = self.driver.find_element(By.CSS_SELECTOR, "body > div.layui-layout.layui-layout-admin > div > div.layui-form.layui-border-box.layui-table-view > div.layui-table-box > div.layui-table-fixed.layui-table-fixed-l > div.layui-table-body > table > tbody > tr:nth-child(10) > td.layui-table-col-special > div > div")
        ActionChains(self.driver).click(enter_btn).perform()
        self.driver.implicitly_wait(10)
        self.driver.find_element(By.XPATH, "//*[@id='table-button-del']").click()
        self.driver.implicitly_wait(10)
        self.driver.find_element(By.CLASS_NAME, "layui-layer-btn0").click()

    def test_delete_user(self):
        self.delete_user()


if __name__ == "__main__":
    unittest.main()
